package com.mrd.netty.thrift;

import com.mrd.thrift.generated.Person;
import com.mrd.thrift.generated.PersonService;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;

/**
 * @author jack
 * @data 2019/5/9 16:40
 */
public class ThrifClient {

    public static void main(String[] args) {
        TFramedTransport transport = new TFramedTransport(new TSocket("localhost", 8899,600 ));
        TCompactProtocol protocol = new TCompactProtocol(transport);
        PersonService.Client client = new PersonService.Client(protocol);

        try {
            transport.open();
            Person person = client.getPersonByUsername("jack");

            System.out.println(person.toString());

            System.out.println("-------");

            Person person2 = new Person();
            person2.setUsername("lisi");
            person2.setAge(12);
            person2.setMarried(true);

            client.savePerson(person2);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);

        } finally {
            transport.close();
        }

    }
}
